﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RMS.Web.Shell.Presenter;
using RMS.Web.Shell.View;
using RMS.Utils.MVP;
using RMS.Utils.Navigator;
using RMS.DataAccess.Entities;

namespace RMS
{
    public partial class BookingRadiologyView : Page<BookingRadiologyPresenter>, IBookingRadiologyView
    {
        RadiologyRequest _RadiologyRequest;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    _RadiologyRequest = this.Presenter.GetBookedRadiology(Convert.ToInt32(Request.QueryString[0].ToString().Decrypt(Constants.ApplicationKey)));
                    BtnSave.Visible = true;
                    btnUpdate.Visible = false;
                    FillForm();
                }
                catch (Exception)
                {

                }

                DdlRadiologytype.DataSource = this.Presenter.GetRadiologyTypes();
                DdlRadiologytype.DataTextField = "RadiologyCode";
                DdlRadiologytype.DataValueField = "RadiologyCode";
                DdlRadiologytype.DataBind();

            }
        }
        private void FillForm()
        {
            DdlRadiologytype.SelectedValue = _RadiologyRequest.RadiologyCode;
            txtdate_CalendarExtender.SelectedDate = _RadiologyRequest.RequestDate;
            TXTPayment.Text = _RadiologyRequest.PatientPay.ToString();
            txtRecetNum.Text = _RadiologyRequest.PayResetNum.ToString();
            if (!_RadiologyRequest.PatientSituation)
                rdbtnSituation.SelectedIndex = 1;

        }
        private void GetFormData()
        {
            _RadiologyRequest.PatientID = this.Presenter.GetPetiontID(TXTPatientname.Text);
            _RadiologyRequest.RadiologyCode = DdlRadiologytype.SelectedValue;
            _RadiologyRequest.RequestDate = Convert.ToDateTime(txtdate.Text);
            _RadiologyRequest.PatientPay = Convert.ToInt32(TXTPayment.Text);
            _RadiologyRequest.PayResetNum = Convert.ToInt32(txtRecetNum.Text);
            if (rdbtnSituation.SelectedIndex == 0)
                _RadiologyRequest.PatientSituation = true;
            else
                _RadiologyRequest.PatientSituation = false;
        }
        protected void BtnSave_Click(object sender, EventArgs e)
        {
            _RadiologyRequest = new RadiologyRequest();
            GetFormData();
            this.Presenter.insertBookingRadiology(_RadiologyRequest);
            Notification.Show("Save Sussefuly");
        }

        protected void BtnClear_Click(object sender, EventArgs e)
        {
            TXTPatientname.Text = "";
            TXTPatientname.Text = "";
            DdlRadiologytype.SelectedValue = "";
            TXTPayment.Text = "";
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            _RadiologyRequest = this.Presenter.GetBookedRadiology(Convert.ToInt32(Request.QueryString[0].ToString().Decrypt(Constants.ApplicationKey)));
            GetFormData();
            this.Presenter.UpdateRadiologyRequest(_RadiologyRequest);
            Notification.Show("Update Sussefuly");
        }
    }
}